// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//

#pragma once

#include <cstdint>
#include <utility>

#include <nebula/array/data.h>


namespace nebula {
namespace list_util {
namespace internal {

/// \brief Calculate the smallest continuous range of values used by the
/// var-length list-like input (list, map and list-view types).
///
/// \param input The input array such that is_var_length_list_like(input.type)
/// is true
/// \return A pair of (offset, length) describing the range
TURBO_EXPORT turbo::Result<std::pair<int64_t, int64_t>> RangeOfValuesUsed(
    const ArraySpan& input);

/// \brief Calculate the sum of the sizes of all valid lists or list-views
///
/// This is usually the same as the length of the RangeOfValuesUsed() range, but
/// it can be:
/// - Smaller: when the child array contains many values that are not
/// referenced by the lists or list-views in the parent array
/// - Greater: when the list-views share child array ranges
///
/// \param input The input array such that is_var_length_list_like(input.type)
/// is true
/// \return The sum of all list or list-view sizes
TURBO_EXPORT turbo::Result<int64_t> SumOfLogicalListSizes(const ArraySpan& input);

}  // namespace internal

}  // namespace list_util
}  // namespace nebula
